package com.example.demo2.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo2.entity.Validation;
import com.example.demo2.mapper.ValidationMapper;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ValidationService extends ServiceImpl<ValidationMapper, Validation> {

    public void saveCode(String email, String code, Integer type, Date dbTime) {

        Validation validation = new Validation();
        validation.setEmail(email);
        validation.setCode(code);
        validation.setType(type);
        validation.setTime(dbTime);

        //先删除已存在的code
        UpdateWrapper<Validation> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("email", email);
        updateWrapper.eq("type", type);
        remove(updateWrapper);
        save(validation);
    }
}
